<template>
	<view class="mainpadding">
		<view class="flexbetween mainpadding radius tybjs">
			<view class="ershiba xiaobai fonweight">旧密码</view>
			<input class="textright xiaobai" type="text" placeholder="请输入旧密码" v-model="oldpassword">
		</view>
		<view class="flexbetween mainpadding radius tybjs margin_top">
			<view class="ershiba xiaobai fonweight">新密码</view>
			<input class="textright xiaobai" type="text" placeholder="请输入新密码" v-model="password">
		</view>
		<view class="flexbetween mainpadding radius tybjs margin_top">
			<view class="ershiba xiaobai fonweight">新密码</view>
			<input class="textright xiaobai" type="text" placeholder="请再次输入新密码" v-model="passwordt">
		</view>
		<view class="gudingdb mainpadding">
			<view class="bigbtn" @click="submit">确认修改</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				password:"",
				passwordt:"",
				oldpassword:"",
			}
		},
		
		methods: {
			submit(){
				if(this.oldpassword==""){
					httpRequest.toast("请输入旧密码")
					return false
				}
				if(this.password==""){
					httpRequest.toast("请输入新密码")
					return false
				}
				if(this.passwordt==""){
					httpRequest.toast("请再次输入新密码")
					return false
				}
				if(this.passwordt!=this.password){
					httpRequest.toast("两次输入的新密码不一致请重试")
					return false
				}
				uni.showLoading({
					mask:true,
					title:"请稍候"
				})
				httpRequest.request('/api/user/changepwd','GET',{
					oldpassword:this.oldpassword,
					newpassword:this.password,
				}).then(res => {
					uni.hideLoading()
					if(res.code == 1){
						httpRequest.toast('修改成功，系统已为您自动退出登录');
						uni.setStorageSync("user_id",'')
						uni.setStorageSync("token",'')
						setTimeout(()=>{
							uni.navigateBack({
								delta:2
							})
						},1000)
					}else{
						httpRequest.toast(res.msg);
					}
				})
			},
		}
	}
</script>

<style>

</style>
